package com.wz.datachannel.util.log4j;

import java.io.File;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.wz.datachannel.common.GlobalConfig;

import android.os.Environment;

/**
 * log4j日志管理类
 * 
 * @author LW
 *
 */
public class Log4jManager {

	private static Logger mLog4JInstance = null;

	public Log4jManager() {
	}

	public static Logger getInstance() {
		if (mLog4JInstance == null) {
			mLog4JInstance = Logger.getLogger(GlobalConfig.LOG_TAG);
			configure();
		}
		return mLog4JInstance;
	}

	@SuppressWarnings("unused")
	private static void configure() {
		final LogConfigurator logConfigurator = new LogConfigurator();

		if (GlobalConfig.isUseFileAppender
				&& android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {// 有sd卡
			logConfigurator.setFileName(Environment.getExternalStorageDirectory() + File.separator + GlobalConfig.LOG_PATH);
		} else {// 无sd卡
			logConfigurator.setUseFileAppender(false);
		}

		// Set the root log level
		logConfigurator.setRootLevel(GlobalConfig.LOG4J_LEVEL);
		// Set log level of a specific logger
		logConfigurator.setLevel("org.apache", Level.ERROR);
		logConfigurator.configure();
	}

}
